package com.example.mychat.Controller;


import com.example.mychat.Pojo.NewFriend;
import com.example.mychat.Pojo.Result;
import com.example.mychat.Pojo.UserInfo;
import com.example.mychat.Service.FriendService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//@CrossOrigin(origins = "http://localhost:7000")
@CrossOrigin(origins = "*")
@RestController
@Slf4j
public class FriendCtrl {
    @Autowired
    private FriendService friendService;

    @PostMapping("/friendadd")
    public Result newFriend(@RequestBody NewFriend newFriend){
        return friendService.FriendAdd(newFriend);
    }

    @GetMapping("/getfriendinfo")
    public Result getnewfriend(String myId){
        List<UserInfo> userinfo=friendService.SelectFriendInfo(myId);
        return Result.success(userinfo);
    }

    @PostMapping("/checkfriend")
    public Result checkFriend(@RequestBody String input){
        UserInfo checkfriendinfo=friendService.checknewfriend(input);
        return Result.success(checkfriendinfo);
    }

    /**
     * 确认好友请求
     * @param newFriend 实体类
     * @return
     */
    @PostMapping("/friendconfirm")
    public Result confirmFriend(@RequestBody NewFriend newFriend){
        return friendService.confirmFriendRequest(newFriend);
    }

    /**
     * 好友删除操作
     * @param newFriend 实体类
     * @return
     */
    @DeleteMapping("/deletefriend")
    public Result deleteFriend(@RequestBody NewFriend newFriend){
        return friendService.deleteFriend(newFriend);
    }



    @GetMapping("/getNewfriend")
    public Result getNewFriendList(String myid){
        log.info("获取验证消息列表："+myid);
        return friendService.getmynewFriendList(myid);
    }
}
